import { co, Group, z } from "jazz-tools";

export const Dog = co.map({
  name: z.string(),
});

export const Person = co.map({
  name: z.string(),
  age: z.number(),
  dog: Dog,
});

export const People = co.list(Person);

export const Root = co.map({
  people: People,
});

export const TestAccount = co
  .account({
    profile: co.profile(),
    root: Root,
  })
  .withMigration((account) => {
    if (!account.$jazz.refs.root) {
      const publicGroup = Group.create();
      publicGroup.makePublic("writer");

      account.$jazz.set(
        "root",
        Root.create(
          {
            people: [
              { name: "John", age: 30, dog: { name: "Rex" } },
              { name: "Mathieu", age: 30, dog: { name: "Bibi" } },
            ],
          },
          publicGroup,
        ),
      );
    }
  });
